function flatern(arr) {
    const isDeep = arr.some(item => item instanceof Array)
    if (!isDeep) {
        return arr
    }
    const res = Array.prototype.concat.apply([], arr)  // [].concat(...arr)
    return flatern(res)
}

const res = flatern([1, 2, [3, 4], 5])
console.log(res)
